package com.mconnect.msurvey.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "survey")
public class Survey implements Serializable{
	private int id_survey;
	private Date date_survey;
	private String region;
	private String typeOfSurvey;
	private String agree = "NIE";
	private User id_user;
	private List<Category> categoryList;
	private Responder id_responder;
	private List<Questions> questionsList;
	private List<TechnicalQuestions> technicalQuestionsList;
	private SurveyPlan id_plan;
	private int id_userRecommend;
	
	@Id
	@GeneratedValue
	public int getId_survey() {
		return id_survey;
	}
	public void setId_survey(int id_survey) {
		this.id_survey = id_survey;
	}
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDate_survey() {
		return date_survey;
	}
	public void setDate_survey(Date date_survey) {
		this.date_survey = date_survey;
	}
	public String getRegion() {
		return region;
	}
	public void setRegion(String region) {
		this.region = region;
	}
	@OneToOne(targetEntity=User.class, cascade = CascadeType.ALL, fetch=FetchType.LAZY)
    @JoinColumn(name = "id_user", referencedColumnName="id_user" )
	@Fetch(FetchMode.SELECT)
	public User getId_user() {
		return id_user;
	}
	public void setId_user(User id_user) {
		this.id_user = id_user;
	}
	@OneToMany(mappedBy="id_category", cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
	@Fetch(FetchMode.SELECT)
	public List<Category> getCategoryList() {
		return categoryList;
	}
	public void setCategoryList(List<Category> categoryList) {
		this.categoryList = categoryList;
	}
	@OneToOne(targetEntity=Responder.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "id_responder", referencedColumnName="id_responder" )
	@Fetch(FetchMode.SELECT)
	public Responder getId_responder() {
		return id_responder;
	}
	public void setId_responder(Responder id_responder) {
		this.id_responder = id_responder;
	}
	@OneToMany(mappedBy="id_question", cascade={CascadeType.ALL}, fetch=FetchType.LAZY)
	@Fetch(FetchMode.SELECT)
	public List<Questions> getQuestionsList() {
		return questionsList;
	}
	public void setQuestionsList(List<Questions> questionsList) {
		this.questionsList = questionsList;
	}
	
	public String getTypeOfSurvey() {
		return typeOfSurvey;
	}
	public void setTypeOfSurvey(String typeOfSurvey) {
		this.typeOfSurvey = typeOfSurvey;
	}
	
	@OneToMany(mappedBy="id_technical", cascade={CascadeType.ALL})
	@Fetch(FetchMode.SELECT)
	public List<TechnicalQuestions> getTechnicalQuestionsList() {
		return technicalQuestionsList;
	}
	public void setTechnicalQuestionsList(
			List<TechnicalQuestions> technicalQuestionsList) {
		this.technicalQuestionsList = technicalQuestionsList;
	}
	@OneToOne(targetEntity=SurveyPlan.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "id_plan", referencedColumnName="id_plan" )
	@Fetch(FetchMode.SELECT)
	public SurveyPlan getId_plan() {
		return id_plan;
	}
	public void setId_plan(SurveyPlan id_plan) {
		this.id_plan = id_plan;
	}
	
	/**
	 * Zgoda na przetwarzanie danych osobowych
	 * @return
	 */
	@Column(length=10)
	public String getAgree() {
		return agree;
	}
	public void setAgree(String agree) {
		if(!agree.isEmpty())
			this.agree = agree;
	}
	
	@Column(length=10)
	public int getId_userRecommend() {
		return id_userRecommend;
	}
	public void setId_userRecommend(int id_userRecommend) {
		this.id_userRecommend = id_userRecommend;
	}
	@Override
	public String toString() {
		return "Survey [id_responder=" + id_responder + "]";
	}
	
	
	
	 
	
	

}
